package com.gnar.rest;

import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioGroup;

public class RestaurantAppActivity extends Activity {
	List<Restaurant> model = new ArrayList<Restaurant>();
	ArrayAdapter<Restaurant> adapter = null;
    ArrayAdapter<String> addr_adapter = null;
	String location[] = new String[] { };
	AutoCompleteTextView addr = null;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button save = (Button)findViewById(R.id.save);
        ListView list = (ListView)findViewById(R.id.restaurants);
        adapter = new ArrayAdapter<Restaurant>(this,android.R.layout.simple_list_item_1,model);
        addr = (AutoCompleteTextView) findViewById(R.id.addr);
        addr_adapter = new ArrayAdapter<String>(this, R.layout.addr_view, location);
        addr.setAdapter(addr_adapter);
 
        list.setAdapter(adapter);
        
        save.setOnClickListener(onSave);
	}
    
    private View.OnClickListener onSave = new View.OnClickListener() {
		
		public void onClick(View v) {
			Restaurant r = new Restaurant();
			EditText name = (EditText)findViewById(R.id.name);
			RadioGroup types = (RadioGroup)findViewById(R.id.types);
			
			r.setAddress(addr.getText().toString());
			r.setName(name.getText().toString());
			
			switch (types.getCheckedRadioButtonId()){
			case R.id.eat_in:
				r.setType("eat_in");
				break;
			case R.id.take_out:
				r.setType("take_out");
				break;
			case R.id.delivery:
				r.setType("delivery");
				break;
			}
			name.setText("");
			addr.setText("");
			addr_adapter.add(r.getAddress());
			adapter.add(r);
		}
	};
}